<html>
<head><meta charset="utf-8"><title>Transmutability Intrinsic · project-safe-transmute · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/index.html">project-safe-transmute</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html">Transmutability Intrinsic</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202615282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202615282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202615282">(Jul 01 2020 at 19:44)</a>:</h4>
<p>Did it come up in the lang meeting or did I miss the discussion proposing it? It looks kinda neat, including the sealed <code>: UnsafeTransmuteOptions</code> bound. I'd like to know more if there has been anything covering it.</p>



<a name="202619288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202619288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202619288">(Jul 01 2020 at 20:19)</a>:</h4>
<p>This document provides an overview: <a href="https://hackmd.io/@jswrenn/HydSGVHS8">https://hackmd.io/@jswrenn/HydSGVHS8</a></p>
<p>In short: while knowing statically that a transmutation is perfectly sound and safe is really nice, sometimes it's desirable to be able to relax certain static checks. For instance, this implementation of bytemuck's <code>try_cast_ref</code> turns off the static alignment check, and the person writing that function takes it on themselves to do a dynamic check instead: <a href="https://docs.rs/typic/0.3.0/src/typic/lib.rs.html#275-286">https://docs.rs/typic/0.3.0/src/typic/lib.rs.html#275-286</a></p>



<a name="202662751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202662751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202662751">(Jul 02 2020 at 08:38)</a>:</h4>
<p>Ah, so it comes from Typic's options/relax system. The name <code>Options</code> doesn't really imply that it can turn _off_ checks for me. Is there any more information the intended semantics of the embodiment as a const-fn specifically? Further, any particular reason why Options is not a simple opaque struct as an arguments to the const-fn or just similarity of design? Talking about this from the other hackmd</p>
<blockquote>
<p><code>const fn can_transmute&lt;Src, Dst, Options&gt; -&gt; bool</code></p>
</blockquote>



<a name="202662904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202662904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202662904">(Jul 02 2020 at 08:41)</a>:</h4>
<p>I had advocated simplifying the compiler builtin transmute checks by taking them out of the type system and into a const-fn before, so I'm quite happy some of that got in the draft :)</p>



<a name="202695155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202695155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202695155">(Jul 02 2020 at 14:24)</a>:</h4>
<blockquote>
<p>Is there any more information the intended semantics of the embodiment as a const-fn specifically?</p>
</blockquote>
<p>Not yet, but you should think of it as embodying typic's <code>UnsafeTransmuteFrom</code> trait. Typic's documentation on safety and soundness applies, just mentally replace "produces a compile error" in the docs with "returns false" when thinking about <code>can_transmute</code>.</p>
<p>Once const generics advances a bit, libcore can implement typic-style <code>TransmuteFrom</code> traits just based on whether or not that predicate is satisfied.</p>



<a name="202695572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202695572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202695572">(Jul 02 2020 at 14:27)</a>:</h4>
<blockquote>
<p>Further, any particular reason why Options is not a simple opaque struct as an arguments to the const-fn or just similarity of design?</p>
</blockquote>
<p>It's for consistency with the transmutation marker traits: those take a type parameter <code>Options</code>. In theory, const generics could be used here. There's a few major points in favor of using a type parameter for this instead of const generics:</p>
<ul>
<li>stabilizing the various transmutation marker trait definitions isn't blocked on stabilizing const generics</li>
<li>rust supports default type parameters. In the common case, you probably don't want to neglect any guarantees.</li>
</ul>



<a name="202697396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202697396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202697396">(Jul 02 2020 at 14:40)</a>:</h4>
<p>What about stability guarantees in comparison to the traits? How are they defined? For example, <code>neglect::Stability</code> as an option kind and bounding some public transmute impl always seemed contradictory for the standard library. Either the set of impl is stable anyways, or it is not in which case it violates the stability guarantees. The bool return of course doesn't necessarily need to adhere to such strict guarantees.</p>
<blockquote>
<p>In theory, const generics could be used here. </p>
</blockquote>
<p>I see. Having a type parameter even allows both options to be used in the future when const generics stabilize, by <br>
creating some newtype with a const generic parameter supplying the 'computed' value.</p>



<a name="202697677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202697677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202697677">(Jul 02 2020 at 14:42)</a>:</h4>
<p>Without the dependency on const generics it even seem <em>far</em> easier to establish the intrinsic than the marker traits. Almost no dependencies except implementation of layout comparison in the compiler, and without any impl stability risk.</p>



<a name="202703120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202703120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202703120">(Jul 02 2020 at 15:23)</a>:</h4>
<blockquote>
<p>What about stability guarantees in comparison to the traits?</p>
</blockquote>
<p>I'm not sure I understand your question exactly, but I think what you're getting at is that in zerocopy, for instance,  if a type implements<code>FromBytes</code>, it's a statement that it's safe, sound <em>and</em> stable to instantiate a value of that type from arbitrary initialized bytes. </p>
<p>In Typic, if a type implements <code>FromBytes&lt;()&gt;</code>, it's <em>also</em> a statement that it's safe, sound <em>and</em> stable to instantiate a value of that type from arbitrary initialized bytes. </p>
<p>However, Typic also lets you finely &amp; explicitly opt-out down stability, safety and (some) soundness guarantees. The reason it has all this flexibility is because it aims for a future where if you ever find yourself needing to resort to <code>mem::transmute</code>, it means you're doing something that cannot possibly be sound.</p>
<p>You define the stability properties of your types by implementing one or both of <a href="https://docs.rs/typic/0.3.0/typic/stability/index.html">two traits</a>: <code>TransmutableFrom</code> and <code>TransmutableInto</code>.</p>



<a name="202708552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202708552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202708552">(Jul 02 2020 at 16:03)</a>:</h4>
<p>What I'm getting at is: If in one version of Rust the intrinsic retruns <code>true</code>, will it do so in any future as well? That's the promise that trait impls deliver, removing an impl is a breaking change. This seems sightly problematic from two perspectives: There is no equivalent of the <code>#[unstable]</code> attribute for the return value so it's hard to experiment with new attributes or more guarantees in nightly. And secondly the <code>neglect::Stability</code> runs counter to that very promise that is foundational to <code>std</code>, I think this should be much more explicit than simply choosing another type.<br>
Problem one might be solved by not returning a bool but an enum with one <code>Unstable</code> variant, where that unstable variant is only return on an unstable compiler with an active feature gate.<br>
Problem two seems harder.</p>



<a name="202708786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202708786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202708786">(Jul 02 2020 at 16:05)</a>:</h4>
<blockquote>
<p>What I'm getting at is: If in one version of Rust the intrinsic retruns true, will it do so in any future as well?<br>
Notwithstanding soundness bugs (which should be fixed): yes. That's the promise. This intrinsic must never return <code>true</code> incorrectly.</p>
</blockquote>



<a name="202709165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202709165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202709165">(Jul 02 2020 at 16:08)</a>:</h4>
<blockquote>
<p>And secondly the neglect::Stability runs counter to that very promise that is foundational to std, I think this should be much more explicit than simply choosing another type.</p>
</blockquote>
<p>I don't follow. I think we might not be on the same page. The design of typic (and this RFC) is compatible with the standard library's API stability guarantees. <code>neglect::Stability</code> doesn't affect the standard library's API stability guarantees.</p>



<a name="202709432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202709432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202709432">(Jul 02 2020 at 16:10)</a>:</h4>
<blockquote>
<blockquote>
<p>What I'm getting at is: If in one version of Rust the intrinsic retruns true, will it do so in any future as well?</p>
</blockquote>
<p>Yes</p>
</blockquote>
<p>But if I query with <code>neglect::Stability</code> then the answer is No, that's the whole point. I might incidentally get a <code>true</code> when trying to transmute <code>enum { Yes, No }</code> to <code>bool</code>, and at a later point when the compiler chooses different discriminants I get <code>false</code>. This seems to me as if  <code>neglect::Stability</code> is not the same as the others.</p>



<a name="202709821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202709821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202709821">(Jul 02 2020 at 16:14)</a>:</h4>
<p>Ah, no, that's not the case. <code>neglect::Stability</code> is <em>strictly</em> limited to whether the <code>TransmutableFrom</code> and <code>TransmutableInto</code> bounds are enforced. Typic will forbid an<code>enum { Yes, No } to bool</code> <em>even if you neglect <strong>all</strong> static checks</em> because that enum's layout is totally undefined.</p>



<a name="202710527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202710527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202710527">(Jul 02 2020 at 16:19)</a>:</h4>
<p>Ohhh, that's fancy. I think I see the difference now.</p>



<a name="202710777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202710777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202710777">(Jul 02 2020 at 16:21)</a>:</h4>
<p>I'm still not convinced it's ever really a good idea to use as a library author but at least it's coherent</p>



<a name="202710790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202710790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202710790">(Jul 02 2020 at 16:21)</a>:</h4>
<p>In other words: <code>neglect::Stability</code> isn't really about stability across rust versions, it's about stability across library versions.</p>



<a name="202710862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202710862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202710862">(Jul 02 2020 at 16:22)</a>:</h4>
<p>Yeah, library authors should almost never use <code>neglect::Stability</code>, except for one case:</p>



<a name="202712381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202712381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202712381">(Jul 02 2020 at 16:34)</a>:</h4>
<p>Rust currently does not give library authors a way to declare their public layout stability guarantees across versions. If a library author currently wants to convey that their type will <em>always</em> be transmutable into an array of 32 bytes, they'll mark their type as <code>#[repr(C)]</code> and then write a rustdoc comment stating their promise. In the future envisioned by this RFC, stating that API promise will be as simple as implementing <code>TransmutableFrom</code> for their type.</p>
<p>There's going to be a transition period where library consumers should be encouraged to move away from using <code>mem::transmute</code> (which is wildly unsafe and unsound), but are going to be still relying on crate versions that predate <code>TransmutableFrom</code> and <code>TransmutableInto</code>. The <code>neglect::Stability</code> option lets them make this transition without throwing <em>all</em> safety and soundness guarantees out the window.</p>



<a name="202712834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202712834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202712834">(Jul 02 2020 at 16:38)</a>:</h4>
<p>So it's 'private definition is part of SemVer', isn't it? That seems very coarse, being able to declare size and align stable independently of each other comes to mind as a potentially interesting intermediate. But I guess it's a start and better than relying on documentation alone.</p>



<a name="202713542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202713542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202713542">(Jul 02 2020 at 16:44)</a>:</h4>
<p>Surprisingly, <code>TransmutableFrom</code> and <code>TransmutableInto</code> are ridiculously powerful for expressing that sort of stuff!</p>
<p>For instance, let's say I always want to guarantee that a type <code>Foo</code> is at least 10 bytes, but absolutely <em>nothing</em> else about it.</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#[repr(C)]</span><span class="w"> </span><span class="k">struct</span> <span class="nc">TenBytes</span><span class="p">([</span><span class="n">MaybeUninit</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="p">;</span><span class="w"> </span><span class="mi">10</span><span class="p">]);</span><span class="w"></span>

<span class="k">unsafe</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="n">TransmutableInto</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TenBytes</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="202723840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202723840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pachi <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202723840">(Jul 02 2020 at 18:03)</a>:</h4>
<p><span class="user-mention" data-user-id="219211">@Jack Wrenn</span> All that is superinteresting (public layout guarantees for reprC and others, interim guarantees, etc), and I think it should appear someway in the RFC (or whatever doc that is proposed). It may even pave a way to some form of intermediate ABI IIUC. Great work!</p>



<a name="202733706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202733706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202733706">(Jul 02 2020 at 19:20)</a>:</h4>
<p><span class="user-mention" data-user-id="125416">@pachi</span> I anticipate striking a balance of what to include will be a challenge of writing this RFC. :-) For understanding stability and options, the big-picture view of a <code>TransmuteFrom</code> trait seems really helpful!</p>
<p>One approach might be presenting this big-picture view but including a prominent 'Roadmap' section that plainly lays out the order of operations:</p>
<ul>
<li>first and foremost landing the transmutation marker traits, the stability traits and the intrinsic.</li>
<li>then <em>eventually</em> landing the <code>(Unsafe?)Transmute{From,Into}</code> traits using that intrinsic, and using those to blanket-impl the marker traits</li>
</ul>
<p>...and provides a rationale (landing the marker traits first meets immediate demand and can be done without closing the door on sound+complete general transmutation).</p>



<a name="202735775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202735775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202735775">(Jul 02 2020 at 19:38)</a>:</h4>
<p>Part of the rationale for this particular two-step approach is that I'm <em>assuming</em> that the only way to implement a type depending on whether a <code>const</code> predicate is satisfied depends on const generics: <a href="https://github.com/rust-lang/rust/pull/70107#issuecomment-652584108">https://github.com/rust-lang/rust/pull/70107#issuecomment-652584108</a></p>
<p>But, if there's a quick-and-dirty <em>extra-linguistic</em> mechanism in rustc for this (i.e., where the compiler itself temporarily has special knowledge of <code>TransmuteFrom</code> and can impl it based on the outcome of <code>can_transmute</code>), then there's no need for the RFC to talk about the general transmutation traits like they're glimpses into the far-flung future.</p>
<p>I don't know how the compiler knows when to implement <code>Sized</code>, <code>Send</code> and <code>Sync</code>, but maybe that same mechanism could make a <code>TransmuteFrom&lt;Src&gt;</code> trait work  <em>before</em> const generics progresses substantially? <span class="user-mention" data-user-id="116009">@nikomatsakis</span>?</p>



<a name="202736467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/202736467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#202736467">(Jul 02 2020 at 19:43)</a>:</h4>
<p>Oooo, there's the <code>Freeze</code> trait, too, which is implemented extra-linguistically: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html#method.is_freeze">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html#method.is_freeze</a></p>
<p>In the case of <code>TransmuteFrom</code> and company, the extra-linguistic nature of the <code>impl</code> would be temporary.</p>



<a name="203042622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203042622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203042622">(Jul 06 2020 at 21:25)</a>:</h4>
<p><span class="user-mention" data-user-id="219211">@Jack Wrenn</span> so -- Send and Sync are implemented using <em>auto traits</em></p>



<a name="203042645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203042645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203042645">(Jul 06 2020 at 21:25)</a>:</h4>
<p>basically, an <code>auto trait Foo</code> is "automatically implemented" for a type <code>T</code> if all data embedded in <code>T</code> implements the trait</p>



<a name="203042652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203042652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203042652">(Jul 06 2020 at 21:25)</a>:</h4>
<p>you can opt out with <code>!Foo</code> impls</p>



<a name="203042658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203042658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203042658">(Jul 06 2020 at 21:25)</a>:</h4>
<p>this mechanism is not currently stable</p>



<a name="203042714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203042714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203042714">(Jul 06 2020 at 21:26)</a>:</h4>
<p><code>Sized</code> is different and is hard-coded into rustc</p>



<a name="203042736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203042736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203042736">(Jul 06 2020 at 21:26)</a>:</h4>
<p>in both cases, we are conservative around generic types like <code>T</code>, and you just have to have a where clause in scope that <code>T: Send</code> or <code>T: Sized</code>, etc</p>



<a name="203043120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203043120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203043120">(Jul 06 2020 at 21:30)</a>:</h4>
<p>For the reference-level explanation, I'm trying to gauge what's involved in going from having a <code>can_transmute</code> intrinsic, to having a trait that represents the same thing. Const-generics provides a long-term in-language answer, but since that's (relatively) far into the future, I'm curious what in-compiler mechanisms there are for this. The implementation of the <code>Freeze</code> trait seems similar, at a glance.</p>



<a name="203105890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Transmutability%20Intrinsic/near/203105890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Transmutability.20Intrinsic.html#203105890">(Jul 07 2020 at 13:59)</a>:</h4>
<p>(deleted)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>